<!--
功能：模型功能对话框
作者：李成
时期：2023年11月30日
-->
<script setup lang="ts">
import { ref, onMounted, reactive } from "vue";
import type { reqExeFun } from "./utils/types.ts";
const subItem = reactive({
  funID: 0,
  tableName: "",
  ids: "",
  currText: "",
  contrlID: 0,
  contrText: ""
});
const arrItem = ref([]);
const isRadio = ref(false);
const checkArr = ref([]);
const props = withDefaults(defineProps<reqExeFun>(), {
  funID: 0,
  tableName: "",
  ids: "",
  currText: "",
  contrlID: 0,
  contrText: ""
});

onMounted(() => {
  subItem.funID = props.funID;
  subItem.tableName = props.tableName;
  subItem.ids = props.ids;
  // subItem.currText = props.currText;
  subItem.contrlID = props.contrlID;
  subItem.contrText = props.contrText;
  if (props.currText != null && props.currText.length > 0) {
    checkArr.value = props.currText.split(",");
  }
  if (subItem.contrlID == 3) {
    if (subItem.contrText.indexOf("$") !== -1) {
      arrItem.value = subItem.contrText.split("$");
      isRadio.value = true;
    } else {
      arrItem.value = subItem.contrText.split("#");
      isRadio.value = false;
    }
  }
});

const getReulst = () => {
  if (!isRadio.value && checkArr.value.length > 0) {
    checkArr.value.forEach(elment => {
      subItem.currText += elment + ",";
    });
    subItem.currText = subItem.currText.substring(
      0,
      subItem.currText.length - 1
    );
  }
  return subItem;
};

defineExpose({ getReulst });
//const emit = defineEmits(["delModel"]);
</script>

<template>
  <el-input
    v-model="subItem.currText"
    placeholder="请输入内容"
    v-if="contrlID == 2"
  />
  <el-radio-group v-model="subItem.currText" class="ml-4" v-if="isRadio">
    <el-radio
      :label="item"
      size="large"
      v-for="(item, key) in arrItem"
      :key="key"
    />
  </el-radio-group>
  <el-checkbox-group v-model="checkArr" v-if="!isRadio" class="ml-4">
    <el-checkbox :label="item" v-for="(item, key) in arrItem" :key="key" />
  </el-checkbox-group>
</template>
